package com.wpzf.zxhc.service.impl;

import com.wpzf.zxhc.domain.WpCjTbhcjg2023DTO;
import com.wpzf.zxhc.mapper.WpzfUnitHcTaskMapper;
import com.wpzf.zxhc.mapper.WpzfZgTbTaskMapper;
import com.wpzf.zxhc.service.WpzfUnitHcTaskService;
import com.wpzf.zxhc.service.WpzfZgTbTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class WpzfZgTbTaskServiceImpl implements WpzfZgTbTaskService {

    @Autowired
    WpzfZgTbTaskMapper wpzfZgTbTaskMapper;

    @Override
    public Integer zgSubmit(Map<String, Object> parms) {
        List<Map<String,Object>> list = wpzfZgTbTaskMapper.queryZgtbByTbbh(parms);
        if (list!=null) {
            wpzfZgTbTaskMapper.updateZgtbState(parms);
        }
        parms.put("submitdate",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
        return wpzfZgTbTaskMapper.zgSubmit(parms);
    }

    @Override
    public int update_unit_zgtb_state(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.update_unit_zgtb_state(parms);
    }

    @Override
    public List<Map<String, Object>> query_unit_zgtb_pch(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_zgtb_pch(parms);
    }

    @Override
    public List<Map<String, Object>> query_unit_user_dzgtb_list(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_user_dzgtb_list(parms);
    }

    @Override
    public Integer query_unit_user_dzgtb_list_count(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_user_dzgtb_list_count(parms);
    }

    @Override
    public List<Map<String, Object>> query_unit_user_dzgtb_leftlist(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_user_dzgtb_leftlist(parms);
    }

    @Override
    public List<Map<String, Object>> query_unit_user_yzgtb_list(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_user_yzgtb_list(parms);
    }

    @Override
    public Integer query_unit_user_yzgtb_list_count(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_user_yzgtb_list_count(parms);
    }

    @Override
    public List<Map<String, Object>> query_unit_user_yzgtb_leftlist(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_user_yzgtb_leftlist(parms);
    }

    @Override
    public List<Map<String, Object>> query_unit_pch(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_pch(parms);
    }

    @Override
    public List<Map<String, Object>> query_unit_dzgtb_list(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_dzgtb_list(parms);
    }

    @Override
    public int query_unit_dzgtb_list_count(Map<String, Object> parms) {
        Integer count=0;
        Map<String, Object> map = wpzfZgTbTaskMapper.query_unit_dzgtb_list_count(parms);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> query_unit_yzgtb_list(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_yzgtb_list(parms);
    }

    @Override
    public int query_unit_yzgtb_list_count(Map<String, Object> parms) {
        Integer count=0;
        Map<String, Object> map = wpzfZgTbTaskMapper.query_unit_yzgtb_list_count(parms);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public Map<String, Object> query_unit_zgtbbyid(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_unit_zgtbbyid(parms);
    }

    @Override
    public int update_unit_zgtb(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.update_unit_zgtb(parms);
    }

    @Override
    public List<Map<String, Object>> query_jl_zgtb_pch(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_jl_zgtb_pch(parms);
    }

    @Override
    public List<Map<String, Object>> query_jl_user_dzgtb_list(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_jl_user_dzgtb_list(parms);
    }

    @Override
    public Integer query_jl_user_dzgtb_list_count(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_jl_user_dzgtb_list_count(parms);
    }

    @Override
    public List<Map<String, Object>> query_jl_user_dzgtb_leftlist(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_jl_user_dzgtb_leftlist(parms);
    }

    @Override
    public List<Map<String, Object>> query_jl_user_yzgtb_list(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_jl_user_yzgtb_list(parms);
    }

    @Override
    public Integer query_jl_user_yzgtb_list_count(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_jl_user_yzgtb_list_count(parms);
    }

    @Override
    public List<Map<String, Object>> query_jl_user_yzgtb_leftlist(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.query_jl_user_yzgtb_leftlist(parms);
    }

    @Override
    public Integer zgtbSubmit(Map<String, Object> parms) {
        Integer rest = 0;
        List<Map<String,Object>> list = (List<Map<String, Object>>) parms.get("selectList");
        if (list!=null) {
            for (Map<String, Object> map : list) {
                WpCjTbhcjg2023DTO wpCjTbhcjg2023DTO = wpzfZgTbTaskMapper.queryZgtb(map);
                if (wpCjTbhcjg2023DTO!=null) {
                    map.put("hcjgsm",wpCjTbhcjg2023DTO.getHcjgsm());
                    if ("合法".equals(wpCjTbhcjg2023DTO.getPdlx())) {
                        map.put("zphlxjc",wpCjTbhcjg2023DTO.getHfZphlxjc());
                        map.put("yxzpdl",wpCjTbhcjg2023DTO.getHfYxzpdl());
                    } else if ("违法".equals(wpCjTbhcjg2023DTO.getPdlx())) {
                        map.put("zphlxjc",wpCjTbhcjg2023DTO.getWfZphlxjc());
                        map.put("yxzpdl",wpCjTbhcjg2023DTO.getWfYxzpdl());
                    } else if ("其他".equals(wpCjTbhcjg2023DTO.getPdlx())) {
                        map.put("zphlxjc",wpCjTbhcjg2023DTO.getQtZphlxjc());
                        map.put("yxzpdl",wpCjTbhcjg2023DTO.getQtYxzpdl());
                    }
                }
                wpzfZgTbTaskMapper.updateShywhj(map);
                rest += wpzfZgTbTaskMapper.zgtbSubmit(map);
            }
        }
        return rest;
    }

    @Override
    public WpCjTbhcjg2023DTO queryZgtb(Map<String, Object> parms) {
        return wpzfZgTbTaskMapper.queryZgtb(parms);
    }

}
